package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.BrandBO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.vo.BrandVO;
import com.cskaoyan.bean.vo.TVO;
import com.cskaoyan.service.BrandService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author by WANGJun
 * @date 2022/6/5 15:07
 */
@RestController
@RequestMapping("admin/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    @GetMapping("list")
    public BaseRespVo list(BaseParam baseParam,Integer id,String name){
        TVO<BrandVO> brandVOS = brandService.listBrand(baseParam, id,name);
        return BaseRespVo.ok(brandVOS);}

     @PostMapping("create")
    public BaseRespVo create(@RequestBody BrandBO brandBO){
        if (brandBO.getPicUrl()==null){return BaseRespVo.err("请上传图片",400);}
        if (!StringUtils.isNumeric(brandBO.getFloorPrice().toString())){return BaseRespVo.err("price必须为数字",400);}
        brandBO.setAddTime(new Date());
        BrandVO brandVO = brandService.createBrand(brandBO);
        return BaseRespVo.ok(brandVO);}

     @PostMapping("update")
    public BaseRespVo update(@RequestBody BrandBO brandBO){
         BrandVO brandVO = brandService.updateBrand(brandBO);
         return BaseRespVo.ok(brandVO);}

     @PostMapping("delete")
    public BaseRespVo delete(@RequestBody BrandBO brandBO){
        brandService.deleteBrand(brandBO.getId());
        return BaseRespVo.ok(null);}

}
